package com.pug.zixun.controller.order;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pug.zixun.service.order.IOrderService;
import com.pug.zixun.pojo.Order;
import com.pug.zixun.vo.OrderVo;
import com.pug.zixun.bo.OrderBo;
import com.pug.zixun.commons.enums.ResultStatusEnum;
import com.pug.zixun.commons.ex.PugValidatorException;
import com.pug.zixun.commons.utils.fn.asserts.Vsserts;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import com.pug.zixun.controller.BaseController;
import java.util.List;
import org.pug.generator.anno.PugDoc;
/**
 * OrderController
 * 创建人:yykk<br/>
 * 时间：2022-08-09 23:06:29 <br/>
 * 源码下载：前台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-ui.git
 * 飞哥B站地址：后台代码 git clone https://gitee.com/kekesam/kuangstudy-pug-parent.git
 * @version 1.0.0<br/>
 *
*/

@RestController
@RequiredArgsConstructor
@Slf4j
@PugDoc(name="订单列表",tabname="kss_order")
public class OrderController extends BaseController{

    private final IOrderService orderService;



	/**
	 * 查询订单列表列表信息并分页
	 * @path : /admin/order/load
     * @method: findOrders
     * @param : orderVo
     * @result : IPage<OrderBo>
	 * 创建人:yykk
	 * 创建时间：2022-08-09 23:06:29
	 * @version 1.0.0
	*/
    @PostMapping("/order/load")
    @PugDoc(name="查询订单列表列表信息并分页")
    public IPage<OrderBo> findOrders(@RequestBody OrderVo orderVo) {
        return orderService.findOrderPage(orderVo);
    }


    /**
     * 根据订单列表id查询明细信息
     * @method: get/{id}
     * @path : /admin/order/get/{id}
     * @param : id
     * @result : OrderBo
     * 创建人:yykk
     * 创建时间：2022-08-09 23:06:29
     * @version 1.0.0
    */
    @PostMapping("/order/get/{id}")
    @PugDoc(name="根据订单列表id查询明细信息")
    public OrderBo getOrderById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
           throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return orderService.getOrderById(new Long(id));
    }


	/**
	 * 保存和修改订单列表
     * @method: saveupdate
	 * @path : /admin/order/save
     * @param : order
     * @result : OrderBo
	 * 创建人:yykk
	 * 创建时间：2022-08-09 23:06:29
	 * @version 1.0.0
	*/
    @PostMapping("/order/saveupdate")
    @PugDoc(name="保存和修改订单列表")
    public OrderBo saveupdateOrder(@RequestBody Order order) {
        return orderService.saveupdateOrder(order);
    }


    /**
	 * 根据订单列表id删除订单列表
     * @method: delete/{id}
     * @path : /admin/order/delete/{id}
     * @param : id
     * @result : int
	 * 创建人:yykk
	 * 创建时间：2022-08-09 23:06:29
	 * @version 1.0.0
	*/
    @PostMapping("/order/delete/{id}")
    @PugDoc(name="根据订单列表id删除订单列表")
    public int deleteOrderById(@PathVariable("id") String id) {
        if(Vsserts.isEmpty(id)){
            throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return orderService.deleteOrderById(new Long(id));
    }


   /**
   	 * 根据订单列表ids批量删除订单列表
     * @method: order/delBatch
     * @path : /admin/order/delBatch
     * @param : orderVo
     * @result : boolean
   	 * 创建人:yykk
   	 * 创建时间：2022-08-09 23:06:29
   	 * @version 1.0.0
   	*/
    @PostMapping("/order/delBatch")
    @PugDoc(name="根据订单列表ids批量删除订单列表")
    public boolean delOrder(@RequestBody OrderVo orderVo) {
        log.info("你要批量删除的IDS是:{}", orderVo.getBatchIds());
        if (Vsserts.isEmpty(orderVo.getBatchIds())) {
            throw new PugValidatorException(ResultStatusEnum.ID_NOT_EMPTY);
        }
        return orderService.delBatchOrder(orderVo.getBatchIds());
    }
}
